import requests
import parsel
import re


url = 'https://www.mkzhan.com/216191/'#目录页
headers={
 'user-agent': 'Mozilla/5.e (Windons NI 18.8; Winb4;x54)AppleWebkit/537.36(KHIML,like Gecko) Chrome/113.0.0.8 Safari/537.36', 'x-requested-with': 'XMLiIttpHequest',
}
response = requests.get(url=url, headers=headers)
selector = parsel.Selector(response.text)
lis = selector.css('.chapter__item ')
for li in list(reversed(lis)):
    title = li.css('a::text').getall()[-1].strip()
    chapter_id = li.css('a::attr(data-chapterid)').get()
    #print(title,chapter_id)
    #https://comic.mkzcdn.com/chapter/content/v1/?chapter_id=1004107&comic_id=209412&format=1&quality=1&sign=60832a09913175292a4133ff456d1b97&type=1&uid=65590441
    link = 'https://comic.mkzcdn.com/chapter/content/v1'
    data={
    'chapter_id': chapter_id,
    'comic_id' : '216191',
    'format': '1',
    'quality': '1',
    'sign': '60832a09913175292a4133ff456d1b97',
    'type': '1',
    'uid': '65590441',
    }
    json_data = requests.get(url=link,params=data,headers=headers).json()
    print(title,chapter_id)
    new_title = re.sub(r'[\/:*?"<>|]','',title)
    print(new_title)
    
       
      